package com.tree.thrive.adapter.openapi;

import com.alibaba.fastjson.JSON;
import com.tree.thrive.adapter.openapi.config.log.annoation.LogBizReqParameters;
import com.tree.thrive.business.input.domain.dto.InputCheckResultDTO;
import com.tree.thrive.business.input.domain.req.InputCheckReq;
import com.tree.thrive.business.input.service.InputCheckService;
import com.tree.thrive.global.util.TopTreeBeanUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * learning
 *
 * @Auther: cheng.tang
 * @Date: 2022/4/27 5:43 AM
 * @Description:
 */
@Tag(name = "用户信息校验")
@RestController
@Slf4j
public class InputCheckController {

    @Autowired
    private InputCheckService inputCheckService;

    @LogBizReqParameters
    @Operation(summary = "用户信息处理", description = "有个长度限制")
    @PostMapping("/users")
    public InputCheckResultDTO inputCheck(@RequestBody InputCheckReq req) {
        log.info("请求参数 {}", JSON.toJSONString(req));
        return inputCheckService.handle(req);
    }


    @LogBizReqParameters
    @Operation(summary = "查询用户信息", description = "有个长度限制")
    @GetMapping("/users")
    public List<InputCheckResultDTO> listUsers(InputCheckReq req) {
        log.info("查询用户信息 请求参数 {}", JSON.toJSONString(req));
        return Collections.singletonList(TopTreeBeanUtils.copyProperties(req, InputCheckResultDTO.class));
    }

}
